package com.yanqu.road.server.cmd.activity.rankunionwar.cross;

import com.yanqu.road.entity.activity.rankunionwar.config.RankUnionWarConfig;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.RankUnionWarProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.rankunionwar.RankUnionWarModule;
import com.yanqu.road.server.manger.activity.ActivityMgr;
import com.yanqu.road.server.manger.activity.rankunionwar.RankUnionWarMgr;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.GameProtocol;

@Cmd(code = GameProtocol.S_RANKUNIONWAR_CROSS_GET_LOOK_REWARD, desc = "")
public class RankUnionWarCrossGetLookRewardCmd extends AbstractCommand {


    RankUnionWarProto.RankUnionWarGetLookRewardRespMsg reqMsg;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        reqMsg = RankUnionWarProto.RankUnionWarGetLookRewardRespMsg.parseFrom(packet.getBytes());
        ret = reqMsg.getRet();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        RankUnionWarConfig config = RankUnionWarMgr.getConfig();
        if (config == null || !ActivityMgr.activityInShowTime(config.getActivityInfo())) {
            ret = GameErrorCode.E_ACTIVITY_NO_FOUND;
            return;
        }
        String reward = "";
        if(ret == 0){
            reward = RankUnionWarMgr.getConfig().getLookReward();
            ret = player.getModule(RankUnionWarModule.class).getLookReward(reqMsg.getTurn(),reward);
        }
        RankUnionWarProto.RankUnionWarGetLookRewardRespMsg.Builder respMsg = RankUnionWarProto.RankUnionWarGetLookRewardRespMsg.newBuilder();
        respMsg.setRet(ret);
        if(ret == 0){
            respMsg.setReward(reward);
        }
        player.sendPacket(ClientProtocol.U_RANKUNIONWAR_GET_LOOK_REWARD, respMsg);
    }

    @Override
    public void sendData(GamePlayer player) {

    }
}
